<template>
  <div class="container">
    <!-- 侧边栏 -->
    <aside :class="['sidebar', { collapsed: isCollapsed }]" id="sidebar">
      <div class="sidebar-header">
        <button class="toggle-btn" @click="toggleSidebar">
          <svg class="icon" viewBox="0 0 24 24">
            <path :d="isCollapsed ? 'M5 12h14M12 5l7 7-7 7' : 'M19 12H5M12 19l-7-7 7-7'" />
          </svg>
        </button>
        <h3 v-show="!isCollapsed">开发工具箱</h3>
      </div>

      <div class="tool-list">
        <div class="category-group">
          <h4 class="category-title">格式化工具</h4>
          <ul     v-if="selectedTool!=undefined">
            <li 
            v-for="tool in tools" 
            :key="tool.id" 
            :class="['tool-item', { active: selectedTool === tool.value }]" 
            @click="selectTool(tool.value )"
          >
            <span class="tool-name">{{ tool.name }}</span>
        </li>
          </ul>
         
        </div>
      </div>
    </aside>

    <!-- 主内容区 -->
    <main class="main-content">
      <div class="loading-indicator" v-show="isLoading"></div>
      <transition name="fade" mode="out-in">
        <div 
          class="tool-detail" 
          v-if="selectedTool!=undefined"
          :class="{ active: selectedTool }" 
        >  
         <profitLossCalculator  v-if="selectedTool=='profitLossCalculator'" />
         <fixed_investment_tool  v-if="selectedTool=='fixed_investment_tool'"/>
         <gridTrading  v-if="selectedTool=='gridTrading'"/>
         <buy_shell_income  v-if="selectedTool=='buy_shell_income'"/>
        </div>
     
      </transition>
    </main>
  </div>
</template>

<script setup>

import { ref } from 'vue'
import profitLossCalculator from "./profitLossCalculator.vue";
import fixed_investment_tool from "./fixed_investment_tool.vue";
import gridTrading from "./gridTrading.vue";
import buy_shell_income from "./buy_shell_income.vue";
const isCollapsed = ref(false)
const isLoading = ref(false)
const selectedTool = ref(
  'profitLossCalculator'
)

const tools = ref([
 {
    value: 'profitLossCalculator',
    name: '盈亏计算工具',
  },
  {
    value: 'fixed_investment_tool',
    name: '基金定投收益计算器',
  },{
    value: 'gridTrading',
    name: '网格交易收益计算',
  },{
    value: 'buy_shell_income',
    name: '买入卖出收益计算',
  }
])
const toggleSidebar = () => {
  isCollapsed.value = !isCollapsed.value
}

const selectTool = (tool) => {
  isLoading.value = true;
  selectedTool.value = tool;
  setTimeout(() => {
    isLoading.value = false
  }, 800)
}
</script>

<style>
body {
  background: linear-gradient(to bottom, #e9f1ff, #f6f9ff);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  overflow-x: hidden;
  background-color: #f5f5f6;
}

.container {
  display: flex;
  min-height: 100vh;
  transition: margin-left 0.3s ease;
  background-color: #cbcbcb;
  background: linear-gradient(135deg, #0066ffc2, #5c42a045);
  backdrop-filter: blur(10px);
}

/* 侧边栏样式 */
.sidebar {
    width: 200px;
    border-radius: 20px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    position: relative;
    color: white;
    padding: 20px;
 margin: 10px 0px 10px 10px;
 z-index: 1;
}

.sidebar.collapsed {
  width: 80px;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  border-bottom: 2px solid #ffffff57;
  padding-bottom: 20px;
}

.toggle-btn {
  background: #ffffffad;
    border: none;
    padding: 10px;
    border-radius: 20px;
    cursor: pointer;
    transition: transform 0.2s, background 0.3s;
    margin-right: 20px;
}

.toggle-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: rotate(180deg);
}

.icon {
  width: 24px;
    height: 24px;
    stroke: #000000;
    font-weight: 600;
}

.tool-list {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
  padding-top: 20px;
  overflow: hidden;
}

.category-title {
  grid-column: 1 / -1;
  color: rgba(255, 255, 255, 0.9);
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 15px;
  text-align: center;
}

.tool-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s, box-shadow 0.3s;
  color: white;
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  display: inline-block;
  margin: 10px 10px 0px 0px;
}

.tool-item.active {
background: linear-gradient(45deg, #f6c33b, #60faacc4);
    transform: scale(1.05);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
    color: black;
    font-weight: 600;
}

.tool-item:hover {
  transform: scale(1.03);
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.2);
}

.tool-icon {
  font-size: 24px;
  margin-bottom: 8px;
}

.tool-name {
  font-size: 12px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100px;
}

/* 主内容区 */
.main-content {
  position: relative;
    margin-left: -10px;
  flex: 1;
  padding: 10px 10px 10px 0px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.loading-indicator {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f4f6;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 40px auto;
}

.tool-detail {
  width: 100%;
  background: white;
  border-radius: 24px;
  padding: 40px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.1);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.tool-detail.active {
  opacity: 1;
  transform: translateY(0);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .tool-list {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    z-index: 100;
    height: 100vh;
    border-radius: 0;
  }
  .main-content {
    padding: 40px 20px;
    margin-left: 60px;
  }
}

/* 过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}
.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>    